<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
                xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdldoc="http://code.google.com/p/wsdldoc">
    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" doctype-public="-//W3C//DTD HTML 4.01//EN"/>
    <xsl:param name="sourceFile"/>
    <xsl:param name="version"/>
    <xsl:variable name="wsdl">
        <xsl:choose>
            <xsl:when test="$sourceFile">
                <xsl:value-of select="$sourceFile"/>
            </xsl:when>
            <xsl:otherwise>Wsdl Documentation</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="/">
        <html>
            <head>
                <title>
                    <xsl:value-of select="$wsdl"/>
                    <xsl:if test="$version">
                        <xsl:text> - Release</xsl:text>
                        <xsl:value-of select="$version"/>
                    </xsl:if>
                </title>
                <style type="text/css">
                    UL {
                    margin: 0px;
                    margin-left: 2em;
                    }

                    TH {
                    background-color: black;
                    color: white;
                    font-size: small;
                    white-space: nowrap;
                    padding: 5px;
                    }

                    TD {
                    border: thin;
                    border-color:black;
                    border-style:ridge;
                    padding: 3px;
                    }

                    TABLE {
                    border-color:black;
                    border-style:solid;
                    border-color: black;
                    border-spacing:5px;
                    border-collapse: collapse;
                    margin-top: 15px;
                    }

                    H1 {
                    text-align: center;
                    font-weight: bold;
                    font-size: 48pt;
                    padding-top: 10px;
                    }

                    H1 p {
                    font-size: large;
                    }

                    H2 {
                    padding-top: 40px;
                    font-size: 32pt;
                    font-weight: bold;
                    }

                    H3 {
                    padding-top: 40px;
                    font-size: 20pt;
                    font-weight: bold;
                    }

                    H4 {
                    margin-bottom: 3px;
                    }

                    .empty {
                    font-style: italic;
                    }

                    BODY {
                    margin: 0;
                    padding-top: 1em;
                    padding-left: 4em;
                    padding-right: 4em;
                    padding-bottom: 1em;
                    color: #000;
                    background: #fff;
                    }

                    .normalLink {
                    }

                    .normal {
                    }

                </style>
            </head>
            <body>
                <h1>
                    <xsl:value-of select="$wsdl"/>
                    <br/>
                    <xsl:if test="$version">
                        <p>Release
                            <xsl:value-of select="$version"/>
                        </p>
                    </xsl:if>
                </h1>
                <h2>Table of contents</h2>
                <h3>Operations</h3>
                <xsl:apply-templates select="wsdl:definitions/wsdl:portType/wsdl:operation" mode="TOC">
                    <xsl:sort select="@name"/>
                </xsl:apply-templates>
                <h3>Simple Types</h3>
                <xsl:apply-templates select="wsdl:definitions/wsdl:types/xsd:schema/xsd:simpleType | document(wsdl:definitions/wsdl:types/xsd:schema/xsd:import/@schemaLocation)/xsd:schema/xsd:simpleType" mode="TOC">
                    <xsl:sort select="@name"/>
                </xsl:apply-templates>
                <h3>Complex Types</h3>
                <xsl:apply-templates select="wsdl:definitions/wsdl:types/xsd:schema/xsd:complexType | document(wsdl:definitions/wsdl:types/xsd:schema/xsd:import/@schemaLocation)/xsd:schema/xsd:complexType" mode="TOC">
                    <xsl:sort select="@name"/>
                </xsl:apply-templates>
                <h2>Operations</h2>
                <xsl:apply-templates select="wsdl:definitions/wsdl:portType/wsdl:operation" mode="normal">
                    <xsl:sort select="@name"/>
                </xsl:apply-templates>
                <h2>Simple Types</h2>
                <xsl:apply-templates select="wsdl:definitions/wsdl:types/xsd:schema/xsd:simpleType | document(wsdl:definitions/wsdl:types/xsd:schema/xsd:import/@schemaLocation)/xsd:schema/xsd:simpleType" mode="normal">
                    <xsl:sort select="@name"/>
                </xsl:apply-templates>
                <h2>Complex Types</h2>
                <xsl:apply-templates select="wsdl:definitions/wsdl:types/xsd:schema/xsd:complexType | document(wsdl:definitions/wsdl:types/xsd:schema/xsd:import/@schemaLocation)/xsd:schema/xsd:complexType" mode="normal">
                    <xsl:sort select="@name"/>
                </xsl:apply-templates>
                <h2>Elements</h2>
                <xsl:apply-templates select="wsdl:definitions/wsdl:types/xsd:schema/xsd:element | document(wsdl:definitions/wsdl:types/xsd:schema/xsd:import/@schemaLocation)/xsd:schema/xsd:element" mode="normal">
                    <xsl:sort select="@name"/>
                </xsl:apply-templates>
            </body>
        </html>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="xsd:simpleType" mode="TOC">
        <xsl:element name="a">
            <xsl:attribute name="class">
                <xsl:value-of select="normalLink"/>
            </xsl:attribute>
            <xsl:attribute name="href">
                <xsl:text>#</xsl:text>
                <xsl:value-of select="@name"/>
            </xsl:attribute>
            <xsl:value-of select="@name"/>
        </xsl:element>
        <br/>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="xsd:complexType" mode="TOC">
        <xsl:element name="a">
            <xsl:attribute name="class">
                <xsl:value-of select="normalLink"/>
            </xsl:attribute>
            <xsl:attribute name="href">
                <xsl:text>#</xsl:text>
                <xsl:value-of select="@name"/>
            </xsl:attribute>
            <xsl:value-of select="@name"/>
        </xsl:element>
        <br/>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="xsd:element" mode="normal">
        <xsl:element name="div">
            <xsl:attribute name="class">
                <xsl:value-of select="normal"/>
            </xsl:attribute>
            <xsl:element name="h3">
                <xsl:attribute name="class">
                    <xsl:value-of select="normal"/>
                </xsl:attribute>
                <xsl:element name="a">
                    <xsl:attribute name="name">
                        <xsl:text>element_</xsl:text>
                        <xsl:value-of select="@name"/>
                    </xsl:attribute>
                    <xsl:value-of select="@name"/>
                </xsl:element>
            </xsl:element>
            <h4>Schema</h4>
            <ul>
                <li>
                    <xsl:value-of select="../@targetNamespace"/>
                </li>
            </ul>
            <xsl:variable name="typeName">
                <xsl:value-of select="@name"/>
            </xsl:variable>
            <xsl:if test="@type">
                <h4>Type</h4>
                <xsl:variable name="typeWithoutNS">
                    <xsl:value-of select="substring-after(@type, ':')"/>
                </xsl:variable>
                <xsl:element name="a">
                    <xsl:attribute name="class">normalLink</xsl:attribute>
                    <xsl:attribute name="href">
                        <xsl:text>#</xsl:text>
                        <xsl:value-of select="$typeWithoutNS"/>
                    </xsl:attribute>
                    <xsl:value-of select="$typeWithoutNS"/>
                </xsl:element>
            </xsl:if>
            <xsl:apply-templates select="xsd:complexContent/xsd:extension" mode="extends"/>
            <xsl:if test="//xsd:complexType[.//xsd:extension[substring-after(@base,':')=$typeName]]">
                <h4>Extended by</h4>
                <ul>
                    <xsl:apply-templates
                            select="//xsd:complexType[.//xsd:extension[substring-after(@base,':')=$typeName]]"
                            mode="referenced">
                        <xsl:sort select="@name"/>
                    </xsl:apply-templates>
                </ul>
            </xsl:if>
            <xsl:if test="//xsd:complexType/xsd:complexContent/xsd:restriction/xsd:attribute[substring-after(@wsdl:arrayType,':')=concat($typeName,'[]')]">
                <h4>Has array type</h4>
                <ul>
                    <li>
                        <xsl:element name="a">
                            <xsl:attribute name="class">normalLink</xsl:attribute>
                            <xsl:attribute name="href">#
                                <xsl:value-of
                                        select="//xsd:complexType[xsd:complexContent/xsd:restriction/xsd:attribute[substring-after(@wsdl:arrayType,':')=concat($typeName,'[]')]]/@name"/>
                            </xsl:attribute>
                            <xsl:value-of
                                    select="//xsd:complexType[xsd:complexContent/xsd:restriction/xsd:attribute[substring-after(@wsdl:arrayType,':')=concat($typeName,'[]')]]/@name"/>
                        </xsl:element>
                    </li>
                </ul>
            </xsl:if>
            <xsl:if test=".//xsd:complexType/xsd:complexContent/xsd:extension">
                <h4>Has Complex Content</h4>
                <xsl:variable name="baseWithNS">
                    <xsl:value-of select=".//xsd:complexType/xsd:complexContent/xsd:extension/@base"/>
                </xsl:variable>
                <xsl:variable name="baseWithoutNS">
                    <xsl:value-of select="substring-after($baseWithNS, ':')"/>
                </xsl:variable>
                <ul>
                    <li>
                        <xsl:element name="a">
                            <xsl:attribute name="class">normalLink</xsl:attribute>
                            <xsl:attribute name="href">#
                                <xsl:value-of select="$baseWithoutNS"/>
                            </xsl:attribute>
                            <xsl:value-of select="$baseWithoutNS"/>
                        </xsl:element>
                    </li>
                </ul>
            </xsl:if>
            <xsl:if test="//xsd:complexType[.//xsd:element[substring-after(@type,':')=$typeName]]">
                <h4>Referenced by</h4>
                <ul>
                    <xsl:apply-templates
                            select="//xsd:complexType[.//xsd:element[substring-after(@type,':')=$typeName]]"
                            mode="referenced">
                        <xsl:sort select="@name"/>
                    </xsl:apply-templates>
                </ul>
            </xsl:if>
            <xsl:choose>
                <xsl:when test="string-length(substring-before($typeName,'Exception')) = 0">
                    <xsl:if test="/wsdl:definitions/wsdl:message[wsdl:part[substring-after(@type,':')=$typeName]]">
                        <h4>Used by</h4>
                        <ul>
                            <xsl:apply-templates
                                    select="/wsdl:definitions/wsdl:message[wsdl:part[substring-after(@type,':')=$typeName]]"
                                    mode="referenced">
                                <xsl:sort select="@name"/>
                            </xsl:apply-templates>
                        </ul>
                    </xsl:if>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:if test="/wsdl:definitions/wsdl:portType/wsdl:operation[wsdl:fault[substring-after(@message,':')=$typeName]]">
                        <h4>Used by</h4>
                        <ul>
                            <xsl:apply-templates
                                    select="/wsdl:definitions/wsdl:portType/wsdl:operation[wsdl:fault[substring-after(@message,':')=$typeName]]"
                                    mode="referenced">
                                <xsl:sort select="@name"/>
                            </xsl:apply-templates>
                        </ul>
                    </xsl:if>
                </xsl:otherwise>
            </xsl:choose>
            <h4>Description</h4>
            <xsl:choose>
                <xsl:when test="starts-with(@name,'ArrayOf')">
                    <xsl:apply-templates select="xsd:complexContent/xsd:restriction/xsd:attribute" mode="array"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates select="xsd:annotation/xsd:documentation"/>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:if test=".//xsd:element">
                <table>
                    <tbody>
                        <tr>
                            <th>Property name</th>
                            <th>Type</th>
                            <th>Required</th>
                            <th>Description</th>
                        </tr>
                        <xsl:apply-templates select=".//xsd:element" mode="details"/>
                    </tbody>
                </table>
            </xsl:if>
            <xsl:if test=".//xsd:simpleType">
                <h4>Simple Type</h4>
                <ul>
                    <xsl:apply-templates select=".//xsd:simpleType" mode="normal">
                        <xsl:sort select="@name"/>
                    </xsl:apply-templates>
                </ul>
            </xsl:if>
        </xsl:element>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="wsdl:operation" mode="TOC">
        <xsl:element name="a">
            <xsl:attribute name="class">
                <xsl:value-of select="normalLink"/>
            </xsl:attribute>
            <xsl:attribute name="href">
                <xsl:text>#operation_</xsl:text>
                <xsl:value-of select="@name"/>
            </xsl:attribute>
            <xsl:value-of select="@name"/>
        </xsl:element>
        <br/>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="xsd:simpleType" mode="normal">
        <xsl:element name="div">
            <xsl:attribute name="class">
                <xsl:value-of select="normal"/>
            </xsl:attribute>
            <h3>
                <xsl:element name="a">
                    <xsl:attribute name="name">
                        <xsl:value-of select="@name"/>
                    </xsl:attribute>
                    <xsl:value-of select="@name"/>
                </xsl:element>
            </h3>
            <h4>Schema</h4>
            <ul>
                <li>
                    <xsl:value-of select="../@targetNamespace"/>
                </li>
            </ul>
            <xsl:if test="@name">
                <xsl:variable name="typeName">
                    <xsl:value-of select="@name"/>
                </xsl:variable>
                <xsl:if test="//xsd:complexType[.//xsd:element[substring-after(@type,':')=$typeName]]">
                    <h4>Referenced by</h4>
                    <ul>
                        <xsl:apply-templates
                                select="//xsd:complexType[.//xsd:element[substring-after(@type,':')=$typeName]]"
                                mode="referenced">
                            <xsl:sort select="@name"/>
                        </xsl:apply-templates>
                    </ul>
                </xsl:if>
                <xsl:if test="/wsdl:definitions/wsdl:message[wsdl:part[substring-after(@type,':')=$typeName]]">
                    <h4>Used by</h4>
                    <ul>
                        <xsl:apply-templates
                                select="/wsdl:definitions/wsdl:message[wsdl:part[substring-after(@type,':')=$typeName]]"
                                mode="referenced">
                            <xsl:sort select="@name"/>
                        </xsl:apply-templates>
                    </ul>
                </xsl:if>
            </xsl:if>
            <h4>Description</h4>
            <xsl:apply-templates select="xsd:annotation/xsd:documentation"/>
            <xsl:choose>
                <!-- Test for enums-->
                <xsl:when test=".//xsd:enumeration">
                    <table>
                        <thead>
                            <tr>
                                <th colspan="3">Allowed enumeration values</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <th>Element</th>
                                <th>Type</th>
                                <th>Description</th>
                            </tr>
                            <xsl:apply-templates select=".//xsd:enumeration" mode="details"/>
                        </tbody>
                    </table>
                </xsl:when>
                <xsl:otherwise>
                    <h4>Restrictions</h4>
                    <ul>
                        <xsl:variable name="baseWithoutNS">
                            <xsl:value-of select="substring-after(xsd:restriction/@base, ':')"/>
                        </xsl:variable>
                        <li>Base type:
                            <xsl:element name="a">
                                <xsl:attribute name="class">normalLink</xsl:attribute>
                                <xsl:attribute name="href">
                                    <xsl:text>#</xsl:text>
                                    <xsl:value-of select="$baseWithoutNS"/>
                                </xsl:attribute>
                                <xsl:value-of select="$baseWithoutNS"/>
                            </xsl:element>
                        </li>
                        <xsl:if test="xsd:restriction/xsd:minLength">
                            <li>Min length:
                                <xsl:value-of select="xsd:restriction/xsd:minLength/@value"/>
                            </li>
                        </xsl:if>
                        <xsl:if test="xsd:restriction/xsd:maxLength">
                            <li>Max length:
                                <xsl:value-of select="xsd:restriction/xsd:maxLength/@value"/>
                            </li>
                        </xsl:if>
                    </ul>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:element>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="xsd:complexType" mode="normal">
        <xsl:element name="div">
            <xsl:attribute name="class">
                <xsl:value-of select="normal"/>
            </xsl:attribute>
            <xsl:element name="h3">
                <xsl:attribute name="class">
                    <xsl:value-of select="normal"/>
                </xsl:attribute>
                <xsl:element name="a">
                    <xsl:attribute name="name">
                        <xsl:value-of select="@name"/>
                    </xsl:attribute>
                    <xsl:value-of select="@name"/>
                </xsl:element>
            </xsl:element>
            <h4>Schema</h4>
            <ul>
                <li>
                    <xsl:value-of select="../@targetNamespace"/>
                </li>
            </ul>
            <xsl:variable name="typeName">
                <xsl:value-of select="@name"/>
            </xsl:variable>
            <xsl:apply-templates select="xsd:complexContent/xsd:extension" mode="extends"/>
            <xsl:if test="../xsd:complexType[.//xsd:extension[substring-after(@base,':')=$typeName]]">
                <h4>Extended by</h4>
                <ul>
                    <xsl:apply-templates
                            select="../xsd:complexType[.//xsd:extension[substring-after(@base,':')=$typeName]]"
                            mode="referenced">
                        <xsl:sort select="@name"/>
                    </xsl:apply-templates>
                </ul>
            </xsl:if>
            <xsl:if test="//xsd:complexType/xsd:complexContent/xsd:restriction/xsd:attribute[substring-after(@wsdl:arrayType,':')=concat($typeName,'[]')]">
                <h4>Has array type</h4>
                <ul>
                    <li>
                        <xsl:element name="a">
                            <xsl:attribute name="class">normalLink</xsl:attribute>
                            <xsl:attribute name="href">#
                                <xsl:value-of
                                        select="//xsd:complexType[xsd:complexContent/xsd:restriction/xsd:attribute[substring-after(@wsdl:arrayType,':')=concat($typeName,'[]')]]/@name"/>
                            </xsl:attribute>
                            <xsl:value-of
                                    select="//xsd:complexType[xsd:complexContent/xsd:restriction/xsd:attribute[substring-after(@wsdl:arrayType,':')=concat($typeName,'[]')]]/@name"/>
                        </xsl:element>
                    </li>
                </ul>
            </xsl:if>
            <xsl:if test="../xsd:complexType[.//xsd:element[substring-after(@type,':')=$typeName]]">
                <h4>Referenced by</h4>
                <ul>
                    <xsl:apply-templates
                            select="../xsd:complexType[.//xsd:element[substring-after(@type,':')=$typeName]]"
                            mode="referenced">
                        <xsl:sort select="@name"/>
                    </xsl:apply-templates>
                </ul>
            </xsl:if>
            <xsl:choose>
                <xsl:when test="string-length(substring-before($typeName,'Exception')) = 0">
                    <xsl:if test="/wsdl:definitions/wsdl:message[wsdl:part[substring-after(@type,':')=$typeName]]">
                        <h4>Used by</h4>
                        <ul>
                            <xsl:apply-templates
                                    select="/wsdl:definitions/wsdl:message[wsdl:part[substring-after(@type,':')=$typeName]]"
                                    mode="referenced">
                                <xsl:sort select="@name"/>
                            </xsl:apply-templates>
                        </ul>
                    </xsl:if>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:if test="/wsdl:definitions/wsdl:portType/wsdl:operation[wsdl:fault[substring-after(@message,':')=$typeName]]">
                        <h4>Used by</h4>
                        <ul>
                            <xsl:apply-templates
                                    select="/wsdl:definitions/wsdl:portType/wsdl:operation[wsdl:fault[substring-after(@message,':')=$typeName]]"
                                    mode="referenced">
                                <xsl:sort select="@name"/>
                            </xsl:apply-templates>
                        </ul>
                    </xsl:if>
                </xsl:otherwise>
            </xsl:choose>
            <h4>Description</h4>
            <xsl:choose>
                <xsl:when test="starts-with(@name,'ArrayOf')">
                    <xsl:apply-templates select="xsd:complexContent/xsd:restriction/xsd:attribute" mode="array"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates select="xsd:annotation/xsd:documentation"/>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:if test=".//xsd:element">
                <table>
                    <tbody>
                        <tr>
                            <th>Property name</th>
                            <th>Type</th>
                            <th>Required</th>
                            <th>Description</th>
                        </tr>
                        <xsl:apply-templates select=".//xsd:element" mode="details"/>
                    </tbody>
                </table>
            </xsl:if>
        </xsl:element>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="wsdl:message" mode="referenced">
        <xsl:variable name="operationName">
            <xsl:choose>
                <xsl:when test="string-length(substring-before(@name,'Request')) &gt; 0">
                    <xsl:value-of select="substring-before(@name,'Request')"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="substring-before(@name,'Response')"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <li>
            <xsl:element name="a">
                <xsl:attribute name="class">normalLink</xsl:attribute>
                <xsl:attribute name="href">
                    <xsl:text>#operation_</xsl:text>
                    <xsl:value-of select="$operationName"/>
                </xsl:attribute>
                <xsl:value-of select="$operationName"/>
            </xsl:element>
        </li>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="wsdl:operation" mode="referenced">
        <li>
            <xsl:element name="a">
                <xsl:attribute name="class">normalLink</xsl:attribute>
                <xsl:attribute name="href">
                    <xsl:text>#operation_</xsl:text>
                    <xsl:value-of select="@name"/>
                </xsl:attribute>
                <xsl:value-of select="@name"/>
            </xsl:element>
        </li>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="xsd:complexType" mode="referenced">
        <li>
            <xsl:element name="a">
                <xsl:attribute name="class">normalLink</xsl:attribute>
                <xsl:attribute name="href">
                    <xsl:text>#</xsl:text>
                    <xsl:value-of select="@name"/>
                </xsl:attribute>
                <xsl:value-of select="@name"/>
            </xsl:element>
        </li>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="xsd:attribute" mode="array">
        <xsl:text>Array of</xsl:text>
        <xsl:variable name="nameWithoutArray">
            <xsl:value-of select="substring-before(@wsdl:arrayType, '[]')"/>
        </xsl:variable>
        <xsl:choose>
            <xsl:when test="starts-with($nameWithoutArray,'xsd:')">
                <xsl:value-of select="$nameWithoutArray"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:variable name="nameWithoutNS">
                    <xsl:value-of select="substring-after($nameWithoutArray, ':')"/>
                </xsl:variable>
                <xsl:element name="a">
                    <xsl:attribute name="class">normalLink</xsl:attribute>
                    <xsl:attribute name="href">
                        <xsl:text>#</xsl:text>
                        <xsl:value-of select="$nameWithoutNS"/>
                    </xsl:attribute>
                    <xsl:value-of select="$nameWithoutNS"/>
                </xsl:element>
            </xsl:otherwise>
        </xsl:choose>
        <br/>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="xsd:extension" mode="extends">
        <xsl:variable name="nameWithoutNS">
            <xsl:value-of select="substring-after(@base, ':')"/>
        </xsl:variable>
        <h4>Extends</h4>
        <ul>
            <li>
                <xsl:element name="a">
                    <xsl:attribute name="class">normalLink</xsl:attribute>
                    <xsl:attribute name="href">
                        <xsl:text>#</xsl:text>
                        <xsl:value-of select="$nameWithoutNS"/>
                    </xsl:attribute>
                    <xsl:value-of select="$nameWithoutNS"/>
                </xsl:element>
            </li>
        </ul>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="xsd:element" mode="details">
        <xsl:variable name="nameWithoutNS">
            <xsl:choose>
                <xsl:when test="contains(@type, ':')">
                    <xsl:value-of select="substring-after(@type, ':')"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="@type"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="refWithoutNS">
            <xsl:choose>
                <xsl:when test="contains(@ref, ':')">
                    <xsl:value-of select="substring-after(@ref, ':')"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="@ref"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:element name="tr">
            <xsl:attribute name="class">
                <xsl:value-of select="normal"/>
            </xsl:attribute>
            <td>
                <xsl:choose>
                    <xsl:when test="@name">
                        <xsl:value-of select="@name"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$refWithoutNS"/>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
            <td>
                <xsl:if test="@maxOccurs != 1">
                    <xsl:text>List of </xsl:text>
                </xsl:if>
                <xsl:choose>
                    <xsl:when test="starts-with(@type,'xsd:') or starts-with(@type,'xs:')">
                        <xsl:value-of select="@type"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:choose>
                            <xsl:when test="string-length(xsd:simpleType/xsd:restriction/@base) = 0">
                                <xsl:element name="a">
                                    <xsl:attribute name="class">normalLink</xsl:attribute>
                                    <xsl:attribute name="href">
                                        <xsl:text>#</xsl:text>
                                        <xsl:value-of select="$nameWithoutNS"/>
                                    </xsl:attribute>
                                    <xsl:value-of select="$nameWithoutNS"/>
                                </xsl:element>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="xsd:simpleType/xsd:restriction/@base"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:otherwise>

                </xsl:choose>
            </td>
            <td>
                <xsl:choose>
                    <xsl:when test="(@nillable='true') or (@minOccurs = 0)">No</xsl:when>
                    <xsl:otherwise>Yes</xsl:otherwise>
                </xsl:choose>
            </td>
            <td>
                <xsl:apply-templates select="xsd:annotation/xsd:documentation"/>
            </td>
        </xsl:element>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="xsd:enumeration" mode="details">
        <tr>
            <td>
                <xsl:choose>
                    <xsl:when test="string-length(@value) = 0">
                        <span class="empty">Blank</span>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="@value"/>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
            <td>
                <xsl:value-of select="../@base"/>
            </td>
            <td>
                <xsl:apply-templates select="xsd:annotation/xsd:documentation"/>
            </td>
        </tr>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="wsdl:operation" mode="normal">
        <xsl:element name="div">
            <xsl:attribute name="class">
                <xsl:value-of select="normal"/>
            </xsl:attribute>
            <xsl:element name="h3">
                <xsl:attribute name="class">
                    <xsl:value-of select="normal"/>
                </xsl:attribute>
                <xsl:element name="a">
                    <xsl:attribute name="name">
                        <xsl:text>operation_</xsl:text>
                        <xsl:value-of select="@name"/>
                    </xsl:attribute>
                    <xsl:value-of select="@name"/>
                </xsl:element>
            </xsl:element>
            <xsl:apply-templates select="wsdl:documentation"/>
            <br/>
            <h4>Request</h4>
            <xsl:variable name="opName" select="@name"/>
            <xsl:variable name="requestMessage">
                <xsl:value-of
                        select="substring-after(../../wsdl:portType/wsdl:operation[@name=$opName]/wsdl:input/@message, ':')"/>
            </xsl:variable>
            <xsl:choose>
                <xsl:when test="../../wsdl:message[@name=$requestMessage]/wsdl:part">
                    <xsl:variable name="requestElement">
                        <xsl:value-of
                                select="substring-after(../../wsdl:message[@name=$requestMessage]/wsdl:part/@element, ':')"/>
                    </xsl:variable>
                    <xsl:element name="a">
                        <xsl:attribute name="href">
                            <xsl:text>#element_</xsl:text>
                            <xsl:value-of select="$requestElement"/>
                        </xsl:attribute>
                        <xsl:value-of select="$requestElement"/>
                    </xsl:element>
                </xsl:when>
                <xsl:otherwise>
                    <span class="empty">Empty</span>
                </xsl:otherwise>
            </xsl:choose>
            <h4>Response</h4>
            <xsl:variable name="responseMessage">
                <xsl:value-of
                        select="substring-after(../../wsdl:portType/wsdl:operation[@name=$opName]/wsdl:output/@message, ':')"/>
            </xsl:variable>
            <xsl:choose>
                <xsl:when test="../../wsdl:message[@name=$responseMessage]/wsdl:part">
                    <xsl:variable name="responseElement">
                        <xsl:value-of
                                select="substring-after(../../wsdl:message[@name=$responseMessage]/wsdl:part/@element, ':')"/>
                    </xsl:variable>
                    <xsl:element name="a">
                        <xsl:attribute name="href">
                            <xsl:text>#element_</xsl:text>
                            <xsl:value-of select="$responseElement"/>
                        </xsl:attribute>
                        <xsl:value-of select="$responseElement"/>
                    </xsl:element>
                </xsl:when>
                <xsl:otherwise>
                    <span class="empty">Empty</span>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="wsdl:fault">
                <br/>
                <h4>Faults</h4>
                <table>
                    <tbody>
                        <tr>
                            <th>Fault</th>
                            <th>Description</th>
                        </tr>
                        <xsl:apply-templates select="wsdl:fault" mode="details">
                            <xsl:sort select="@name"/>
                        </xsl:apply-templates>
                    </tbody>
                </table>
            </xsl:if>
        </xsl:element>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="wsdl:message" mode="normal">
        <table>
            <tbody>
                <tr>
                    <th>Parameter name</th>
                    <th>Type</th>
                    <th>Element</th>
                    <th>M</th>
                    <th>Constraints</th>
                    <th>Description</th>
                </tr>
                <xsl:apply-templates select="wsdl:part" mode="details"/>
            </tbody>
        </table>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="wsdl:part" mode="details">
        <xsl:variable name="nameWithoutNS">
            <xsl:value-of select="substring-after(@type, ':')"/>
        </xsl:variable>
        <xsl:variable name="elementNameWithoutNS">
            <xsl:value-of select="substring-after(@element, ':')"/>
        </xsl:variable>
        <xsl:element name="tr">
            <xsl:attribute name="class">
                <xsl:value-of select="normal"/>
            </xsl:attribute>
            <td>
                <xsl:value-of select="@name"/>
            </td>
            <td>
                <xsl:choose>
                    <xsl:when test="starts-with(@type,'xsd:')">
                        <xsl:value-of select="@type"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:element name="a">
                            <xsl:attribute name="class">normalLink</xsl:attribute>
                            <xsl:attribute name="href">
                                <xsl:text>#</xsl:text>
                                <xsl:value-of select="$nameWithoutNS"/>
                            </xsl:attribute>
                            <xsl:value-of select="$nameWithoutNS"/>
                        </xsl:element>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
            <td>
                <xsl:element name="a">
                    <xsl:attribute name="class">normalLink</xsl:attribute>
                    <xsl:attribute name="href">
                        <xsl:text>#element_</xsl:text>
                        <xsl:value-of select="$elementNameWithoutNS"/>
                    </xsl:attribute>
                    <xsl:value-of select="$elementNameWithoutNS"/>
                </xsl:element>
            </td>
            <td>Yes</td>
            <td>
                <xsl:apply-templates select="wsdl:documentation"/>
            </td>
        </xsl:element>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="wsdl:fault" mode="details">
        <tr>
            <td>
                <xsl:variable name="nameWithoutNS">
                    <xsl:value-of select="substring-after(@message, ':')"/>
                </xsl:variable>
                <xsl:variable name="elementWithNS">
                    <xsl:value-of select="//wsdl:message[@name=$nameWithoutNS]/wsdl:part/@element"/>
                </xsl:variable>
                <xsl:choose>
                    <xsl:when test="$elementWithNS">
                        <xsl:variable name="elementWithoutNS">
                            <xsl:value-of select="substring-after($elementWithNS, ':')"/>
                        </xsl:variable>
                        <xsl:element name="a">
                            <xsl:attribute name="class">normalLink</xsl:attribute>
                            <xsl:attribute name="href">
                                <xsl:text>#element_</xsl:text>
                                <xsl:value-of select="$elementWithoutNS"/>
                            </xsl:attribute>
                            <xsl:value-of select="@name"/>
                        </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:element name="a">
                            <xsl:attribute name="class">normalLink</xsl:attribute>
                            <xsl:attribute name="href">
                                <xsl:text>#</xsl:text>
                                <xsl:value-of select="$nameWithoutNS"/>
                            </xsl:attribute>
                            <xsl:value-of select="@name"/>
                        </xsl:element>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
            <td>
                <xsl:apply-templates select="wsdl:documentation"/>
            </td>
        </tr>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="wsdl:documentation">
        <xsl:copy-of select="self::*"/>
    </xsl:template>
    <!-- -->
    <!-- -->
    <!-- -->
    <xsl:template match="xsd:annotation/xsd:documentation">
        <xsl:copy-of select="self::*"/>
    </xsl:template>
</xsl:stylesheet>
